package netmon.gui;

import javax.swing.JProgressBar;

/**
 * Customized JProgressBar with additional methods
 * @author Marc Backes
 */
public class LoadBar extends JProgressBar {
	private static final long serialVersionUID = 1L;
	private double max;										// The maximum value
	private double current;									// The current value

	/**
	 * Constructor: Initialized the bar to 0
	 */
	public LoadBar() {
		max = 0;
		setValue(0);
		setStringPainted(true);
	}

	/**
	 * Set the maximum of the bar
	 * @param max Maximum value
	 */
	public void setMax(double max){
		this.max = max;
		refresh();
	}

	/**
	 * Set the current value of the bar. If the value is a maximum, <i>max</i> is updated
	 * @param current Current value
	 */
	public void setCurrent(double current){
		if(current > max){
			max = current;
		}
		this.current = current;
		refresh();
	}

	/**
	 * Set the maximum value to 0
	 */
	public void resetMax(){
		max = 0;
	}

	/**
	 * Calculates and refreshes the current presentation of the bar
	 */
	public void refresh(){
		setValue((int)((current/max)*100));
		setStringPainted(true);
	}
}
